<template>
  <div class="main-containe">
    <div class="blog-container">
      <p v-if="typeName" v-text="'分类：' + typeName" style="font-size: 24px; color: #000"></p>
      <div class="blog" v-for="item in blogList" :key="item.id">
        <Blog :blog="item"></Blog>
      </div>
    </div>
    <div class="side-container">
      <div class="profile card-box">
        <div class="user-wrapper">
<!--          <img src="http://xiaoshuaiblog.oss-accelerate.aliyuncs.com/config/83d530d0b7d524a41e5927fea1ff6a65.jpg" alt="">-->
          <img :src="$store.state.user.avatar" alt="">
          <div>{{ $store.state.user.name }}</div>
          <span> 小傅背起了行囊的blog，欢迎交流 </span>
        </div>
        <div class="info-wrapper">
          <div class="info-data">
            <div class="div">博客</div>
            <div class="div">{{ blogList.length }}</div>
          </div>
          <div class="info-data">
            <div class="div">分类</div>
            <div class="div">{{ typeList.length }}</div>
          </div>
          <div class="info-data">
            <div class="div">收藏</div>
            <div class="div">{{ collectionList.length }}</div>
          </div>
        </div>
      </div>
      <div class="type card-box">
        <span>博客分类</span>
        <ul>
          <li v-for="item in typeList" :key="item.id">
            <a :href="'/blog?type=' + item.id" v-text="item.name + '(' + item.count + ')'"></a>
          </li>
        </ul>
      </div>
      <div class="recommend card-box">
        <span>推荐排行榜</span>
        <div class="blog-list">
          <div v-for="item in recommendList" :key="item.id" class="blog-item">
            <img :src="path + '/' + item.cover" alt="">
            <div class="content">
              <div class="content-title">
                <a :href="'/detail/' + item.id">{{ item.title }}</a>
              </div>
              <div class="content-time">{{ item.createTime }}</div>
            </div>
          </div>
        </div>
      </div>
      <div class="collection card-box">
        <span>收藏</span>
        <div class="blog-list">
          <div v-for="item in collectionList" :key="item.id" class="blog-item">
            <img :src="path + '/' + item.blog.cover" alt="">
            <div class="content">
              <div class="content-title">
                <a :href="'/detail/' + item.blog.id">{{ item.blog.title }}</a>
              </div>
              <div class="content-time">{{ item.blog.createTime }}</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Blog from './components/Blog'
import {getBlogList, getRecommend} from "../../api/blog/blog";
import {getTypeBlog, getTypeList} from "../../api/blog/type";
import {getCollectionList} from "../../api/blog/collection";

export default {
  components: {Blog},
  data() {
    return {
      path: process.env.VUE_APP_BASE_API,
      blogList: [],
      typeList: [],
      recommendList: [],
      collectionList: [],
      type: this.$route.query.type,
      typeName: null,
      queryParams: {
        pageNum: 1,
        pageSize: 1,
        userId: null,
        status: 1,
      },
      disabled: false
    }
  },
  methods: {
  },
  created() {
    this.$store.dispatch('GetInfo');
    if (this.type != undefined) {
      getTypeBlog(this.type).then(response => {
        this.blogList = response.data;
        this.typeName = response.type;
      });
    } else {
      getBlogList().then(response => {
        this.blogList = response.data;
      });
    }
    getRecommend().then(response => {
      this.recommendList = response.data;
    });
    getTypeList().then(response => {
      this.typeList = response.data;
    });
    getCollectionList().then(response => {
      this.collectionList = response.data;
    })
  }
}
</script>

<style scoped>
.main-containe {
  display: flex;
  flex-wrap: wrap;
  flex: 1 1 auto;
  max-width: 1200px;
  padding: 0 5px;
  margin: 0 auto;
}

.blog-container {
  flex: 0 0 75%;
  max-width: 75%;
  width: 100%;
  padding: 7.5px!important;
}

.side-container {
  flex: 0 0 25%;
  max-width: 25%;
  width: 100%;
  padding: 7.5px!important;
}

.card-box {
  align-items: center;
  width: 100%;
  max-width: 100%;
  margin-top: 20px;
  text-decoration: none;
  outline: none;
  border-radius: 12px 8px 8px 12px;
  background: #fff;
  color: #4c4948;
  box-shadow: 0 4px 8px 6px rgba(7,17,27,.06);
  transition: all .3s;
  overflow-wrap: break-word;
  white-space: normal;
  will-change: box-shadow;
  flex-direction: column;
  align-items: center;
  line-height: 2;
  padding: 1.25rem 1.5rem;
}

.card-box:hover {
  box-shadow: 0 4px 12px 12px rgba(7,17,27,.15);
}

.card-box span {
  font-size: 16px;
}

.card-box ul li {
  list-style-type: none;
}

.card-box ul li a {
  transition: all .3s;
  color: #4c4948;
  text-decoration: none;
}

.card-box ul li a:hover {
  color: #8e8cd8;
}
.user-wrapper {
  text-align: center;
}

.user-wrapper img {
  height: 110px;
  min-width: 110px;
  width: 110px;
  align-items: center;
  border-radius: 50%;
  display: inline-flex;
  justify-content: center;
  line-height: normal;
  position: relative;
  text-align: center;
  vertical-align: middle;
  overflow: hidden;
}

.user-wrapper div {
  font-size: 1.375rem;
  margin-top: 0.625rem;
}

.user-wrapper span {
  font-size: 0.875rem;
}

.info-wrapper {
  display: flex;
  justify-self: center;
  padding: .875rem 0;
  color: #4c4948;
}

.info-data {
  flex: 1;
  text-align: center;
}

.info-data div {
  font-size: 1.25rem;
}

.card-box ul li:before {
  display: inline-block;
  position: relative;
  left: -.75rem;
  width: 12px;
  height: 12px;
  border: .2rem solid #49b1f5;
  border-radius: 50%;
  background: #fff;
  content: "";
  transition-duration: .3s;
}

.blog-item {
  border-bottom: 1px dashed #f5f5f5;
  display: flex;
  align-items: center;
  padding: 6px 0;
}

.blog-item img {
  width: 58.8px;
  height: 58.8px;
  overflow: hidden;
}

.content {
  flex: 1;
  padding-left: 10px;
  word-break: break-all;
  overflow: hidden;
  font-size: 14px;
  /*height: 56px;*/
}

.content-title a:hover {
  color: #2ba1d1;
}

.content-time {
  color: #858585;
  font-size: 85%;
  line-height: 2;
}

.pagination-container {
  background: none;
}
</style>
